#include <iostream>


using namespace std;

class DRAM:public memory{
    public:
        int pagesize;
        int next_acces;
        int current_page;
        DRAM(int page, int nat);
        ~DRAM();
        void mem(bus2_t* line);
        void wrapup();
};

DRAM::DRAM(int page, int nat){

    cycles = 0;
    cache = 0;
    misses = -1;
    conflicts = -1;
    current_page = 0;
    next_acces = nat;
    pagesize = page;
}

//Calls process to process the line and updates cycles and conflicts.
void DRAM::mem(struct bus2_t* line){

    process(line);

    //Determines what page will be used to store the word
    int next_page = (line->address / (pagesize*4))/4;

    //If the same page is used cycles is updated with next acces and 1 cycle for
	//transfer
    if(next_page == current_page){
        cycles += (next_acces + 1);

    //If a new page is used cycles is updated with next acces time, random acces
	//time and 1 cycle for transfer
	}else{
        current_page = next_page;
        cycles += (next_acces + 9);
    }

    conflicts++;

}

//calculates the bandwith and outputs it.
void DRAM::wrapup(){

    bytes = cache * 4;
    bandwidth = (float)bytes/cycles;
    cout <<"output of DRAM with pagesize " << pagesize << "\n Bank conflicts: "
    << conflicts << "\n Bandwidth: " << bandwidth << endl << endl;
}
